<?php

namespace app\common\model\anchor;


use think\Exception;
use think\Model;


class Auit extends Model
{


    // 表名
    protected $name = 'anchor_auit';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [];

    public static function info($user_id)
    {
        return self::where('user_id', $user_id)->find();
    }

    public static function apply($params)
    {
        extract($params);
        $info = self::info($user_id);
        if (!$info) {
            $info = new self();
        } else {
            if ($info->status == 1) {
                throw new Exception('当前认证已完成');
            }
            if ($info->status == 0) {
                throw new Exception("当前认证审核中");
            }
        }
        $info->user_id = $user_id;
        $info->mobile = $phone;
        $info->douyin = $douyin;
        $info->kuaishou = $kuaishou;
        $info->status = 0;
        $result = $info->save();
        return $result;
    }

    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
